class Solution:
    def wiggleMaxLength(self, nums) -> int:
        r = []
        i = 0
        while i<len(nums):
            if len(r)== 0 or len(r) == 1 and r[-1] != nums[i]:
                r.append(nums[i])
            elif r[-1] != nums[i]:
                if r[-2] < r[-1]<nums[i] or r[-2] > r[-1] > nums[i]:
                    r[-1] = nums[i]
                else:
                    r.append(nums[i])
            i+=1
        return len(r)


if __name__ == '__main__':
    so = Solution()
    n = [1,2,3,4,5,6,7,8,9]
    r = so.wiggleMaxLength(n)
    print(r)
